package com.zhongkai.service.impl;

import com.mysql.jdbc.StringUtils;
import com.zhongkai.app.service.IBaseDao;
import com.zhongkai.app.service.LikeService;
import com.zhongkai.model.utils.ZhongkaiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 项目中全部的模糊查询
 * */
@Service
@Transactional(rollbackFor = Exception.class)
public class LikeServiceImpl implements LikeService {


    @Autowired
    private IBaseDao iBaseDao;
    /**
     * 设备号模糊查询
     *
     * @param like_uuid   模糊的设备uuid
     */
    @Override
    public ZhongkaiResult likeUnit(String like_uuid) {


        if (
                StringUtils.isNullOrEmpty(like_uuid)

                ) {
            return ZhongkaiResult.ok();
        }

        List<Object[]> list;

        //SetUnit
        list = iBaseDao.find("select setUuid from SetUnit se where se.setUuid like '" + like_uuid + "%'");
        return ZhongkaiResult.ok(list);
    }


    /**
     * 设备号模糊查询
     *
     * @param like_name   模糊的人员姓名
     */
    @Override
    public ZhongkaiResult likeAppUser(String like_name) {

        if (
                StringUtils.isNullOrEmpty(like_name)

                ) {
            return ZhongkaiResult.ok();
        }




        List list = iBaseDao.find("from AppUser se where se.appName like '%" + like_name + "%'");
        return ZhongkaiResult.ok(list);

    }

    @Override
    public ZhongkaiResult likeSupplierProduct(String product_name) {

        if (
                StringUtils.isNullOrEmpty(product_name)

                ) {
            return ZhongkaiResult.ok();
        }



        List list = iBaseDao.find("from SupplierProduct se where se.proName like '%" + product_name + "%'");


        return ZhongkaiResult.ok(list);
    }


    /**
     * 设备用户名模糊查询
     *
     * @param user_name   模糊的用户姓名
     */
    @Override
    public ZhongkaiResult likeUnitUserName(String user_name) {

        List list = iBaseDao.find("select userName from SetUnit se where se.userName like '%" + user_name + "%'");
        return ZhongkaiResult.ok(list);
    }



    /**
     * 公司产品名称模糊查询
     *
     * @param setmode_name   模糊的公司产品名称
     */
    @Override
    public ZhongkaiResult likeSetmodeName(String setmode_name) {

        List list = iBaseDao.find("select proName from SetProduct se where se.proName like '%" + setmode_name + "%'");
        return ZhongkaiResult.ok(list);
    }

    @Override
    public ZhongkaiResult quunit(String uuid) {
        Object o = iBaseDao.get("select setIp , setStatus from SetUnit se where se.setUuid='" + uuid + "'");
        if (o == null) {
            return ZhongkaiResult.build(500,"此设备不存在");
        }
        return ZhongkaiResult.ok(o);
    }


}
